/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.opmviewer.graphviz;

import java.awt.geom.Point2D;
import java.util.Iterator;
import prefuse.action.layout.Layout;
import prefuse.visual.VisualGraph;
import prefuse.visual.VisualItem;

/**
 *
 * @author grzegorz
 */
public class GraphvizLayout extends Layout {

    String group;

    public GraphvizLayout(String group) {
        this.group = group;
    }

    @Override
    public void run(double fraction) {
        VisualGraph g = (VisualGraph) m_vis.getGroup(group);
        Iterator it = g.nodes();
        Point2D p = getLayoutAnchor();
        double m_x = p.getX();
        double m_y = p.getY();
        while (it.hasNext()) {
            VisualItem n = (VisualItem) it.next();
            double centre_x = n.getDouble("xc") + n.getDouble("w") / 2;
            double centre_y = n.getDouble("yc") + n.getDouble("h") / 2;
            setX(n, null, m_x + centre_x);
            setY(n, null, m_x + centre_y);
        }

    }
}
